<template>
	<view class="">
		<view class="liucheng d-flex align-items justify-content-center">
			<view class="search">
				<u-search placeholder="请输入要查询的内容" placeholderColor="#C9CDD4" :actionStyle="actionStyle" shape="square"
					v-model="keyword" @search="search"></u-search>
			</view>
		</view>
		<!-- <view class="tabs_change d-flex align-items">
			<view class="jf-w" :current="current" @click="chage_tabs(jianfang)"
				v-for="(jianfang,index) in jianfang_lists" :key="index">
				<view :class="current == index ? 'jf-w-t-xz' : 'jf-w-t'">{{jianfang.tabs_name}}</view>
				<view :class="current == index ? 'line' : ''"></view>
			</view>
		</view> -->
		<!-- 商家 -->
		<!-- <view class="" v-if="current == 0">
			<view class="w-690 shopping">
				<view class="d-flex shoplists" @click="gosee(shop)" v-for="(shop,index) in shop_items" :key="index">
					<view class="shopImg-w">
						<image class="shopImg" :src="shop.avatar_url" mode="widthFix"></image>
						<image class="topimg" :src="'../../static/jiaju/top'+(index+1)+'.png'" mode="widthFix"></image>
					</view>
					<view class="">
						<view class="shopName">{{shop.company_name}}</view>
						<view class="">
							<u-rate readonly :count="count" active-color="#FFB400" v-model="shop.star"></u-rate>
						</view>
					</view>
				</view>
			</view>
		</view> -->
		<!-- 商品 -->
		<view class="">
			<view class="top-tabs">
				<scroll-view scroll-x="true" class="scroll-view_H">
					<view class="scroll-view_H-item">
						<view class="top-tabs-pinlei d-flex align-items" :current="pinlei_current"
							@click="pinlei_click(pinlei)" v-for="(pinlei,index) in pinlei_item" :key="index">
							<view :class="pinlei_current == pinlei.id ? 'pinlei-t-xz' :'pinlei-t'">{{pinlei.name}}
							</view>
							<image class="sanjiao" v-if="pinlei_current == pinlei.id" src="../../static/jiaju/xz_sj.png"
								mode="widthFix"></image>
							<image class="sanjiao" v-else src="../../static/jiaju/select.png" mode="widthFix"></image>
						</view>
					</view>
				</scroll-view>
				<!-- 弹窗 -->
				<view class="postion-r">
					<u-transition :show="pinlei_show" mode="fade">
						<view class="pop-pinlei">
							<view class="d-flex align-items fenlei-padding">
								<view class="fenlei" :current="fenlei_cur" @click="fenlei_click(fenlei)"
									v-for="(fenlei,index) in fenlei_items" :key="index">
									<view :class="fenlei_cur == fenlei.id ? 'fenlei-w_xz' : 'fenlei-w'">
										{{fenlei.name}}</view>
								</view>
							</view>
						</view>
					</u-transition>
				</view>

				<!-- 商品 -->
				<view class="shangpin-list">
					<view class="shangpin d-flex align-items justify-content-space-between">
						<view class="shangpin_list" @click="go_shop(shangpin)" v-for="(shangpin,index) in shangpin_items" :key="index">
							<image class="shangpin_phone" :src="shangpin.product_images_first" mode=""></image>
							<view class="">
								<view class="sp-name">{{shangpin.product_name}}</view>
								<view class="sp-num"> <text class="fuhao">￥</text> {{shangpin.price}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		userinfolist,
		getXinxilist,
		getproducttype
	} from '@/api/user.js'
	export default {
		data() {
			return {
				keyword: '',
				page: 1,
				limit: 7,
				actionStyle: {
					color: '#FF6400',
					fontSize: '30rpx',
				},
				// current: 1,
				// jianfang_lists: [{
				// 	tabs_name: '商家',
				// 	id: 0
				// }, {
				// 	tabs_name: '商品',
				// 	id: 1
				// }],
				count: 5,

				shop_items: [],
				pinlei_current: '',
				pinlei_hiden:'',
				pinlei_item: [],
				fenlei_cur: 0,
				fenlei_items: [],
				pinlei_show: false,
				shangpin_items:[],
			}
		},
		onLoad() {
			this.get_leixing()
			this.get_jianfang()
			this.get_pro_list()
		},
		onReachBottom() {
			this.page++
			this.get_jianfang()
			this.get_pro_list()
		},
		onPullDownRefresh() {
			this.page = 1
			this.get_jianfang()
			this.get_pro_list()
		},
		methods: {
			search(e) {
				console.log("eaa", e);
			},
			chage_tabs(e) {
				console.log("建房信息系申诉书", e);
				this.current = e.id
			},
			// 跳转到商家详情
			gosee(e) {
				uni.navigateTo({
					url: '/pagesA/index_top/jianfang_detail?id=' + e.group_id + '&user_id=' + e.user_id
				})
			},
			pinlei_click(e) {
				console.log("点击了哪些品类了", e);
				if(this.pinlei_hiden==e.id){
					this.pinlei_show = !this.pinlei_show
				}else{
					this.pinlei_show = true;
				}
				
				var data = {
					pid: e.id
				}
				getproducttype(data).then(res => {
					console.log("获取产品类型00000",res);
					
					if(res.code == 1){
						let a = []
							a.push({
								id:0,
								name:'全部'
							})
						for (let s of res.data.producttype_list) {
							a.push({
								name: s.name,
								id: s.id
							})
						}
						this.fenlei_items = a
					}
				})
				if(this.pinlei_current == e.id) {
					this.pinlei_current = ''
				}else {
					this.pinlei_current = e.id
				}
				this.pinlei_hiden = e.id
				
			},
			fenlei_click(e) {
				console.log("下一级分类点击",e);
				this.fenlei_cur = e.id
				this.pinlei_show = false
				this.pinlei_current = ''
				this.get_pro_list()
			},
			// 获取建房列表
			get_jianfang() {
				var data = {
					group_id: '6',
					key: this.keyword,
					city_id: uni.getStorageSync('city_id'),
					page: this.page,
					limit: this.limit,
				}
				userinfolist(data).then(res => {
					console.log("获取建房信息列表", res);
					if (res.code == 1) {
						if (this.page == 1) {
							this.shop_items = res.data.list
						} else {
							this.shop_items = this.shop_items.concat(res.data.list)
						}
						uni.stopPullDownRefresh()
					}
				})
			},
			// 获取产品类型
			get_leixing(){
				getproducttype({}).then(res => {
					console.log("获取产品类型",res);
					if(res.code == 1){
						this.pinlei_item = res.data.producttype_list
					}
				})
			},
			// 获取产品信息列表
			get_pro_list(){
				console.log("88888888", this.anli_list);
				var data = {
					page: this.page,
					limit: this.limit,
					type:'11',
					key: this.keyword,
					producttype_id: this.fenlei_cur,
				}
				getXinxilist(data).then(res => {
					console.log("的发生大法师", res);
					if (res.code == 1) {
						if (this.page == 1) {
							this.shangpin_items = res.data.list
						} else {
							this.shangpin_items = this.shangpin_items.concat(res.data.list)
						}
						uni.stopPullDownRefresh()
					}
				})
			},
			go_shop(e){
				uni.navigateTo({
					url:'/pagesA/anli_zhanshi/shopping?id=' + e.content_id
				})
			},
		}
	}
</script>

<style>
	.postion-r {
		width: 750rpx;
		position: relative;
	}

	.shangpin-list {
		margin-top: 40rpx;
	}

	.fuhao {
		font-size: 24rpx;
		font-weight: 600;
		color: #FF4D4F;
	}

	.sp-num {
		font-size: 36rpx;
		font-weight: 600;
		color: #FF4D4F;
		margin: 0rpx 0 15rpx 24rpx;
	}

	.sp-name {
		width: 295rpx;
		font-size: 30rpx;
		color: #333;
		font-weight: 600;
		margin-left: 20rpx;
		margin-top: 20rpx;
		overflow: hidden;
		display: -webkit-box;
		text-overflow: ellipsis;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}

	.shangpin_phone {
		width: 335rpx;
		height: 335rpx;
		display: block;
		border-top-right-radius: 8rpx;
		border-top-left-radius: 8rpx;
	}

	.shangpin_list {
		width: 335rpx;
		background-color: #fff;
		border-radius: 8rpx;
		margin-top: 20rpx;
	}

	.shangpin {
		width: 690rpx;
		margin: auto;
		flex-wrap: wrap;
	}

	.fenlei-padding {
		width: 750rpx;
		flex-wrap: wrap;
	}

	.fenlei-w_xz {
		width: 212rpx;
		height: 76rpx;
		font-size: 26rpx;
		background: #FFEADD;
		color: #FF6400;
		display: flex;
		align-items: center;
		justify-content: center;
		border: 2px solid #FFD8BE;
	}

	.fenlei-w {
		width: 212rpx;
		height: 76rpx;
		font-size: 26rpx;
		color: #333333;
		display: flex;
		align-items: center;
		justify-content: center;
		border: 1px solid #F2F3F5;
	}

	.fenlei {
		width: 33%;
		text-align: center;
		display: flex;
		justify-content: center;
		margin-top: 30rpx;
	}

	.pop-pinlei {
		width: 750rpx;
		position: absolute;
		top: 0;
		padding-bottom: 30rpx;
		background: #FFFFFF;
		margin-top: 32rpx;
		box-shadow: 0rpx 13rpx 12rpx 0rpx #ddd;
		z-index: 2;
	}

	.sanjiao {
		width: 20rpx;
		margin-left: 14rpx;
		display: block;
	}

	.pinlei-t-xz {
		font-size: 26rpx;
		font-weight: 500;
		color: #FF6400;
	}

	.pinlei-t {
		font-size: 26rpx;
		font-weight: 500;
		color: #1A1A1A;
	}

	.scroll-view_H-item {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.scroll-view_H {
		width: 690rpx;
		margin: auto;
		white-space: nowrap;
		margin-top: 40rpx;
	}

	.top-tabs-pinlei {
		/* margin-top: 40rpx;
		margin-right: 45rpx; */
	}

	.top-tabs {
		width: 750rpx;
		/* height: 105rpx; */
	}

	.topimg {
		width: 48rpx;
		display: block;
		position: absolute;
		top: 0;
		left: 0;
	}

	.shopping {
		margin-top: 55rpx;
	}

	.shopName {
		font-size: 32rpx;
		font-weight: 600;
		line-height: 42rpx;
		color: #1C2023;
		margin: 10rpx 0;
	}

	.shoplists {
		margin-top: 30rpx;
	}

	.shopImg {
		width: 160rpx;
		display: block;
	}

	.shopImg-w {
		width: 160rpx;
		height: 160rpx;
		border-radius: 4rpx;
		position: relative;
		margin-right: 20rpx;
	}

	.line {
		width: 48rpx;
		height: 4rpx;
		margin: auto;
		margin-top: 0rpx;
		background: #FF6400;
	}

	.jf-w-t-xz {
		font-size: 32rpx;
		font-weight: 600;
		text-align: center;
		color: #FF6400;
	}

	.jf-w-t {
		font-size: 32rpx;
		font-weight: normal;
		text-align: center;
		color: #1D2129;
	}

	.jf-w {
		width: 50%;
		text-align: center;
		line-height: 80rpx;
		padding-top: 20rpx;
	}

	.tabs_change {
		width: 750rpx;
		height: 102rpx;
		background-color: #fff;
		margin-top: 2rpx;
	}

	.search {
		width: 690rpx;
		margin: auto;
	}

	.liucheng {
		width: 750rpx;
		height: 102rpx;
		background-color: #fff;
	}

	page {
		background-color: #F7F8FB;
	}
</style>